package com.kabuda.zhugehot200_review;

import java.util.Arrays;

/**
 * @author kabuda
 * @date 2025-03-27 22:25
 * @description
 */
public class 寻找数组中心下表 {
    public static void main(String[] args) {
        System.out.println(pivotIndex(new int[]{1, 7, 3, 6, 5, 6}));
    }

    /**
     * @param nums
     * @return
     */
    public static int pivotIndex(int[] nums) {
        int sum = Arrays.stream(nums).sum();
        int total = 0;
        for (int i = 0; i < nums.length; i++) {
            if (2 * total + nums[i] == sum) {
                return i;
            }
            total += nums[i];
        }
        return -1;
    }
}
